package com.wisdom.smartbook.utils;

import android.annotation.SuppressLint;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;

public class DateUtils {

    /**
     * 秒转时间
     *
     * @param time 秒
     * @return 00:00:00
     */
    public static String secToTime(long time) {
        String timeStr = null;
        long hour = 0;
        long minute = 0;
        long second = 0;
        if (time <= 0)
            return "00:00";
        else {
            minute = time / 60;
            if (minute < 60) {
                second = time % 60;
                timeStr = unitFormat(minute) + ":" + unitFormat(second);
            } else {
                hour = minute / 60;
                if (hour > 99)
                    return "99:59:59";
                minute = minute % 60;
                second = time - hour * 3600 - minute * 60;
                timeStr = unitFormat(hour) + ":" + unitFormat(minute) + ":" + unitFormat(second);
            }
        }
        return timeStr;
    }

    public static String unitFormat(long i) {
        String retStr;
        if (i >= 0 && i < 10) {
            retStr = "0" + i;
        } else {
            retStr = "" + i;
        }
        return retStr;
    }

    /**
     * 把毫秒转化成年与日时分秒
     *
     * @param millSec 毫秒数
     * @return yyyy-MM-dd HH:mm:ss 如：2018-12-12 14:58:15
     */
    @SuppressLint("SimpleDateFormat")
    public static String longToMdHms(long millSec) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date(millSec);
        return sdf.format(date);
    }

    /**
     * 获取当前时间到第二天几点的时间差
     */
    public static long getSecondsNextEarlyMorning(int num) {
        Calendar cal = Calendar.getInstance();
        if (cal.get(Calendar.HOUR_OF_DAY) - num >= 0) {
            cal.add(Calendar.DAY_OF_YEAR, 1);
        } else {
            cal.add(Calendar.DAY_OF_YEAR, 0);
        }
        cal.set(Calendar.HOUR_OF_DAY, num);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTimeInMillis() - System.currentTimeMillis();
    }

    /**
     * 获取当前年月日时分
     *
     * @return yyyy-MM-dd HH:mm 如：2018-12-12 15:19
     */
    @SuppressLint("SimpleDateFormat")
    public static String getCurrYMdHms() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        return sdf.format(date);
    }

    /**
     * @param
     * @return
     * @date: 2021/10/14 5:34 下午
     * @description 获取当前月份的日期号码
     */
    public static int getDayOfMonth() {
        Calendar c = Calendar.getInstance();
        return c.get(Calendar.DAY_OF_MONTH);
    }

    /**
     * 把毫秒转化成年月日
     * @return yyyy-MM-dd
     */
    public static String getCurrentDay() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date(System.currentTimeMillis());
        return sdf.format(date);
    }

    public static int generayFaceUpdateRandomHour() {
        int min = 14;
        int max = 16;
        int random = new Random().nextInt((max - min) + 1) + min;
        return random;
    }

    public static int generayRebootRandomHour() {
        int min = 1;
        int max = 4;
        int random = new Random().nextInt((max - min) + 1) + min;
        return random;
    }

    public static int generayAppUpdateRandomHour() {
        int min = 22;
        int max = 23;
        int random = new Random().nextInt((max - min) + 1) + min;
        return random;
    }

    public static int generayRandomMinute() {
        int min = 1;
        int max = 55;
        int random = new Random().nextInt((max - min) + 1) + min;
        return random;
    }

    public static String timeSpan(long diff) {


        long day = diff / (24 * 60 * 60 * 1000);
        long hour = (diff / (60 * 60 * 1000) - day * 24);
        long min = ((diff / (60 * 1000)) - day * 24 * 60 - hour * 60);
        long s = (diff / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
        String result = "" + day + "天" + hour + "小时" + min + "分" + s + "秒";
        return result;

    }

//    public static void main(String[] args) {
//        for (int i = 0; i < 100; i++) {
//            System.out.println("小时=="+generayAMRandomHour()+"分=="+generayRandomMinute()+"秒=="+generayRandomMinute());
//        }
//    }


    public static void main(String args[]){
        String str="C7zZqlEjFeB1YFFiD8YX7LnUMpbsKnLscOSmsTfdjPMN3eL7kQRSa1GHv+jLxyGOXvOTspWb8KxV3b6HmTJ4f+jV541DyxRGvaGaArkoDNeKesv/9oNwBvBs69tVjF9o61c/A6VD5NyMXOlZPCPkRx/GzpWDMH2V7YpgBe5XDiaSGzzz3X7iWG4fqa81SnfAyHzcHYs01vBiEY/WqO++rbLOAZFaPxoh87UBkQD3pIryttMDyTf4fS0ZVFf0Iv7o+08uPjFQGOrpnzHy+lw4wAA+inQhfDk7H4k8Dy5+8r4=";
//        System.out.println(SecurityCoder.getInstance().decrypt(str));
    }


}
